package com.quanfaqiang.demo1.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanfaqiang.demo1.anno.AddLog;
import com.quanfaqiang.demo1.anno.DeleteLog;
import com.quanfaqiang.demo1.anno.UpdateLog;
import com.quanfaqiang.demo1.pojo.Furniture;
import com.quanfaqiang.demo1.pojo.Result;
import com.quanfaqiang.demo1.service.FurnitureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@CrossOrigin()
@RequestMapping("/furniture")
public class FurnitureController {
    @Autowired
    private FurnitureService furnitureService;



    @GetMapping("/SelectAll")
    public Result SelectAll(int currentPage, int pageSize) {
        Page<Furniture> furniturePage = furnitureService.SelectAll(currentPage, pageSize);
        System.out.println(furniturePage);
        return Result.success(furniturePage);
    }


    @DeleteLog
    @DeleteMapping("/deleteId/{id}")
    public Result<String> DeleteId(@PathVariable Integer id) {
        System.out.println(id+"ddddddddddddd");
        furnitureService.DeleteId(id);
        return Result.success("删除成功");
    }

    @DeleteLog
    @DeleteMapping("/deleteMore/{ids}")
    public Result deleteIds(@PathVariable List<Integer> ids) {
        System.out.println(ids+"sssssssssssssssssss");
        furnitureService.deleteIds(ids);
        return Result.success("家具批量删除成功");
    }


    @GetMapping("/selectId")
    public Result SelectId(@RequestParam Integer id) {
        Furniture furniture = furnitureService.SelectId(id);
        System.out.println(id);
        System.out.println(furniture);
        return Result.success(furniture);
    }



    @AddLog
    @PostMapping("/add")
    public Result add(@RequestBody Furniture furniture) {
        System.out.println(furniture);
        furnitureService.Add(furniture);
        return Result.success("添加成功");
    }


    @UpdateLog
    @PutMapping("/update")
    public Result update(@RequestBody Furniture furniture) {
        System.out.println(furniture+"dddddddddddddddd");
        System.out.println(furniture);
        furnitureService.update(furniture);
        return Result.success("修改成功");
    }


    @UpdateLog
    @PatchMapping("/updateAvatar")
    public Result updateAvatar(@RequestParam  String avatarUrl,Integer id){
        System.out.println(avatarUrl);
        furnitureService.updateAvatar(avatarUrl,id);
        return Result.success("更新图片完成");
    }


    @GetMapping("/serchFurniture")
    public Result serchFurniture(Integer number,String furnitureName ,String furniturePhoto,Integer currentPage, Integer pageSize,
    Integer furnitureTypesId,Integer quyuTypesId){
        System.out.println(furnitureTypesId +":"+quyuTypesId);
        Page<Furniture> furniturePage=furnitureService.serchFurniture(number,furnitureName,furniturePhoto,currentPage,pageSize,furnitureTypesId,quyuTypesId);
        return Result.success(furniturePage);
    }

    @GetMapping("/selectFurnitureName")
    public Result selectFurnitureName(String furnitureName,Integer id){
        System.out.println(furnitureName);
        Boolean flag=furnitureService.selectFurnitureName(furnitureName,id);
        System.out.println(flag);
        return Result.success(flag);
    }
    @GetMapping("/selectNumber")
    public Result selectNumber(Integer number){
        System.out.println(number);
        Furniture flag=furnitureService.selectNumber(number);
        System.out.println(flag);
        return Result.success(flag);
    }

}
